package com.brspace.qualitycontrol.controller.admin;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.Engineering;
import com.brspace.qualitycontrol.entity.vo.EngineeringVo;
import com.brspace.qualitycontrol.mapper.EngineeringMapper;
import com.brspace.qualitycontrol.service.EngineeringService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 工程表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-05
 */
@Api(description = "工程建设")
@CrossOrigin
@RestController
@RequestMapping("/admin/engineering")
public class EngineeringController {
    @Resource
    private EngineeringService engineeringService;
    @Resource
    private EngineeringMapper engineeringMapper;
    /**
     * 添加工程建设
     * @return
     */
    @ApiOperation("添加工程")
    @PostMapping("addEng")
    public R addEng(@RequestBody Engineering engine){
        engineeringService.addEng(engine);
        return R.ok();
    }

    /**
     * 查看工程数据
     *@author Hugo
     *@date 2021-04-10 11:44
     **/
    @PostMapping("getInfo/{id}")
    public R getInfo(@PathVariable String id){
        return R.ok().data("list",engineeringService.getById(id));
    }

    /**
     * 获取统计信息
     *@author Hugo
     *@date 2021-04-11 15:30
     **/
    @PostMapping("getTotle")
    public R getTotle(){
        return R.ok().data("list",engineeringService.getTotle());
    }

    /**
     * 获取图表数据
     *@author Hugo
     *@date 2021-04-11 16:30
     **/
    @PostMapping("getChart")
    public R getChart(){
        return R.ok().data("list",engineeringService.getChart());
    }
    /**
     *项目金额top5
     *@author Hugo
     *@date 2021-04-11 16:48
     **/
    @PostMapping("top")
    public R top(){
        return R.ok().data("list", engineeringMapper.selectList(new QueryWrapper<Engineering>().orderByDesc("bidd_price").last("limit 5")));
    }


    /**
     * 工程项目列表
     * @return
     */
    @ApiOperation("工程项目列表")
    @GetMapping("list")
    public R findList(){
        List<Engineering> list = engineeringService.list();
        return R.ok().message("成功！").data("list",list);
    }



    /**
     * 项目工程分页列表
     * @param page
     * @param limit
     * @param engineeringVo
     * @return
     */
    @ApiOperation("项目工程分页列表")
    @PostMapping("list/{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit,
            @ApiParam("查询条件")EngineeringVo engineeringVo){
        Page<Engineering> pageParam = new Page<>(page, limit);
        IPage<Engineering> pageModel = engineeringService.selectPage(pageParam, engineeringVo);
        List<Engineering> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total",total).data("rows",records);
    }
}

